# -*- coding: utf-8 -*-


def generate_sql_from_file(file_name: str):
    with open(file_name) as f:
        lines = f.readlines()
        special_urls = []
        for line in lines:
            if line is None or line == '' or line == '\n':
                print('\n')
            else:
                parts = line.split('=')
                if 'anon' in parts[1]:
                    print(f'insert into `url_anon_rule` (`url_pattern`, `description`) '
                          f'values(\'{parts[0]}\', \'\');')
                else:
                    special_urls.append(parts[0])
        if len(special_urls) > 0:
            print('special urls >>>')
            for item in special_urls:
                print(f'insert into `url_anon_rule` (`url_pattern`, `description`) '
                      f'values(\'{item}\', \'\');')


def find_different(base_file: str, missed_file: str):
    url_set = set()
    with open(missed_file) as missed_f:
        lines = missed_f.readlines()
        for line in lines:
            url_pattern = line.replace('"', '').replace('\n', '')
            url_set.add(url_pattern)

    with open(base_file) as base_f:
        lines = base_f.readlines()
        for line in lines:
            parts = line.split('=')
            url_pattern = parts[0]
            if url_pattern not in url_set and 'authc' not in parts[1]:
                print(f'missed url_pattern: {url_pattern}')


if __name__ == '__main__':
    # generate_sql_from_file('/Users/tianjun315/Desktop/anon_urls.txt')
    find_different('/Users/tianjun315/Desktop/compare_origin.txt', '/Users/tianjun315/Desktop/compare_missed.txt')
